package com.itheima.ticket02;

public class Ticket implements Runnable {
    private int count=100;
  private  Object obj= new Object();
    @Override
    public void run() {

        while (true){
            String name = Thread.currentThread().getName();
            System.out.println(name+"来到了这里");
            synchronized (this) {
                if(count==0){
                    break;
                }else {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    count--;
                    System.out.println(name+"正在卖票,还剩"+count);
                }
            }

        }
    }
}
